const Koa = require('koa')
const router = require('./routers')
const bodyParser = require('koa-bodyparser')

const app = new Koa()

// 使用ctx.body解析中间件
app.use(bodyParser({
  extendTypes: {
    json: ['application/x-javascript'] // will parse application/x-javascript type body as a JSON string
  }
}))

// 加载路由中间件
app.use(router.routes()).use(router.allowedMethods())

app.listen(3000, () => {
  console.log('[demo] route-use-middleware is starting at port 3000')
})